// pages/index/index.js
const jokesData = require('../../data/jokes');
const categoriesData = require('../../data/categories');
Page({
  data: {
    jokes: [],
    categories: [],
    currentPage: 1,
    pageSize: 10
  },
  onLoad: function () {
    this.setData({
      jokes: jokesData,
      categories: categoriesData
    });
  },
  onReachBottom: function () {
    // 模拟分页加载
    let newPage = this.data.currentPage + 1;
    let newJokes = jokesData.slice((newPage - 1) * this.data.pageSize, newPage * this.data.pageSize);
    this.setData({
      jokes: this.data.jokes.concat(newJokes),
      currentPage: newPage
    });
  },
  onJokeTap: function (e) {
    let jokeId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/joke-detail/joke-detail?id=' + jokeId
    });
  },
  onShareAppMessage: function () {
    return {
      title: '段子大全 - 笑话趣味不断更',
      path: '/pages/index/index'
    }
  }
})
